package com.foreknow.springboot.threaddemo;

/**
 * @author xiaoming
 * @version jdk1.8
 * @date 2022/8/11 15:34
 * @function:
 */
public class TestSleepDemo implements Runnable {
    private int ticketNumber = 10;
    @Override
    public void run() {
        while (true){
            if (ticketNumber<=0){
                break;
            }
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第"+ticketNumber--+"票");
        }
    }

    public static void main(String[] args) {
        TestSleepDemo ticket= new TestSleepDemo();
        //创建三个子线程
        new Thread(ticket,"AAA").start();
        new Thread(ticket,"BBB").start();
        new Thread(ticket,"CCC").start();

    }
}
